package Game.Windows 
{
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	/**
	 * ...
	 * @author Yevgeniy Logachev
	 */
	public class MessageWindow
	{
		[Embed(source="../../../res/swf/messageWindow.swf", symbol="window2")]
		public static var WindowClass:Class;
		
		private var m_sprite:MovieClip;
		private var m_anim:MovieClip;
		private var m_buttOk:SimpleButton;
		private var m_buttCancel:SimpleButton;
		
		public function MessageWindow(textTitle:String, messageText:String, buttonOk:String, buttonCancel:String) 
		{
			m_anim = new WindowClass() as MovieClip;
			m_anim.addEventListener(Event.ENTER_FRAME, onUpdate);
			m_sprite = m_anim.getChildByName("MessageWindow") as MovieClip;
			
			m_buttOk = m_sprite.getChildByName("ButtonOk") as SimpleButton;
			m_buttOk.addEventListener(MouseEvent.CLICK, onClickOk);
			m_buttCancel = m_sprite.getChildByName("ButtonCancel") as SimpleButton;
			m_buttCancel.addEventListener(MouseEvent.CLICK, onClickCancel);
			
			var textField:TextField;
			textField = m_sprite.getChildByName("TextTitle") as TextField;
			textField.text = textTitle;
			textField = m_sprite.getChildByName("TextMessage") as TextField;
			textField.text = messageText;
			
			textField = m_sprite.getChildByName("ButtonTextOk") as TextField;
			textField.text = buttonOk;
			textField = m_sprite.getChildByName("ButtonTextCancel") as TextField;
			textField.text = buttonCancel;
			
			//m_anim.gotoAndPlay(0);
			Main.mainSprite.stage.addChild(m_anim);
		}
		
		public function release():void
		{
			m_buttOk.removeEventListener(MouseEvent.CLICK, onClickOk);
			m_buttCancel.removeEventListener(MouseEvent.CLICK, onClickCancel);
			m_anim.removeEventListener(Event.ENTER_FRAME, onUpdate);
			
			Main.mainSprite.stage.removeChild(m_anim);
			m_sprite = null;
			m_buttOk = null;
			m_buttCancel = null;
		}		
		
		public function onClickOk(e:MouseEvent):void
		{
			
		}
		
		public function onClickCancel(e:MouseEvent):void
		{
			release();
		}
		
		public function onAnimEnd(e:Event):void
		{
			trace("dfd");
		}
		
		public function onUpdate(e:Event):void
		{
			if (m_anim.currentFrame == m_anim.totalFrames)
			{
				m_anim.gotoAndStop(m_anim.totalFrames);
			}
		}
	}

}